#ifndef __DATA_DB_HPP__
#define __DATA_DB_HPP__

#include <memory>
#include <mutex>
#include <string>
#include <vector>
#include <SqliteDB.h>
#include <QueryResultSet.h>
#include <PreparedStatement.h>
#include "dpparam.hpp"
#include "channel.h"

using namespace std;

/*
创建数据库，读取数据库参数
1. channel   每个通道相关信息
2. channel_dp 每个点位的dp参数
*/
class DtDb{
public:
    DtDb();
    virtual ~DtDb();
#if 1
    static shared_ptr<DtDb> getInstance();
    static void destoryInstance(DtDb* x);
#endif

public:
    void open(string dbFullName);
    void close();
    void test_db();
    
    
    //tabel channel
    int  get_channels(vector<shared_DChannelPtr>& chs);
    //tabel channel_dp
    int  get_channel_dps(vector<shared_DChanneldpPtr>&);
    int  get_channel_dps(int chid,vector<shared_DChanneldpPtr>&);
    void db_lock();
    void db_unlock();
    bool db_islock();
    string getDBfullName();
private:
    SqliteDB*  m_pSqliteDB;

private:
    mutex  m_dbMu;
    string m_dbFullName;
    bool   m_dbLock;
};

typedef shared_ptr<DtDb> DtDb_Ptr;

shared_ptr<DtDb> confdb_getInstance();

#endif